<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="hexinyang">
<title>PSAM卡售卡</title>
<script language="javascript" src="../script/common.js"
	type="text/javascript"></script>
<script language="javascript" src="../script/card.js"
	type="text/javascript"></script>
<script language="javascript" type="text/javascript"
	src="../script/print.js"></script>
<script type="text/javascript">    
	//页面控件初始化
	var org = Common.cOrg();	//当前单位	
	var qt;
	var dataMap = {}
	function load(){
		Eui.showNavigation();
		setPages(["readcardview","detview"]);
		
		searchForm.organization.value = org.id;
		searchForm.cardType.value = BaseCardType.PSAM;
		createTable();
	}
	
	/**
	 * 选择商户
	 */
	function selectStation(){
		SystemMgnt.selStation(function(v){
	 		searchForm.shop.value = v.id;
	 		searchForm.shopName.value = v.name;
	 		searchForm.uniqueId.value = v.uniqueId;
		},{orgId:org.id,selOne:true,orgLevel:Constants.ORG_LEVEL_STATION})
	}
	
	//PSAM信息例表
	function createTable(){
		var columns = [];
		columns[0] = {title:"ID",type:"checkbox"};
		columns[1] = {title:"卡号"};
		columns[2] = {title:"卡片类型"};
		columns[3] = {title:"卡片状态"};
		columns[4] = {title:"卡片库存状态"};
		qt = new QueryTable(null,null,"cardlistview",columns,{
			title : "待领卡片列表",
			columnsConf : false,
			isPage : false,
			buttons:[
				{name:"btn",value:"删除",actions:onDelete},
			]
		});
		qt.dataSrc = {start:0,maxResult:100,total:100,objects:[]}
		qt.showTable();
	}	
	
	function onDelete(){
		var objs = qt.getBoxValue(true);
		if (objs.length<1) {showWarning("请选择需要从待选卡片列表中删除的卡片！");return;}
		var list = []
		var m = {}
		for (var i=0;i<objs.length;i++){
			var l = objs[i];
			var asn = l[1];
			m[asn] = true;
		}
		for (var i=0;i<qt.dataSrc.objects.length;i++){
			var l = qt.dataSrc.objects[i];
			var asn = l[1];
			if (m[asn])
				dataMap[asn] = null;
			else
				list.push(l)
		}
		qt.dataSrc.objects = list;
		qt.dataSrc.total = list.length;
		qt.showTable();
	}
	//显示列表
	function showTable(){
		qt.showTable()
	}
	
	//读卡
	function selCard(){
		if (!searchForm.shop.value) {showWarning("请选择加油站！");return};
		try{
			var psamCard = getPsamTN()
			var data = DWR.syncCall("mgntQueryService.getCardInfo",psamCard.PsamSN);
			var c = data.card;
			CardMgnt.throwIssueErr(c,data.cardType,Constants.PSAM);
			if (dataMap[c.asn]) {showWarning("卡片"+c.asn+"已经在领用列表中！");return};
			dataMap[c.asn] = true;
			qt.dataSrc.objects.push([c.id,c.asn,Common.getText("base_card_type",c.baseCardType),Common.getText(CardStatus.CATEGORY,c.status),Common.getText(CardStoreStatus.CATEGORY,c.storeStatus)])
			qt.dataSrc.total = qt.dataSrc.objects.length
			qt.showTable();
		}catch(e){
			showError(e.description);
		}
	}
	
	//显示领用明细
	function showIssueDet(data){
		switchPage("detview");
		Eui.getBillHtml("billview",{queryName:"issue_psam_bill",
				logId:data.logId
		})	
		try{WebPrint.print('billview');}catch(e){showWarning("打印出错："+e.description);return;}
	}
	function issueOperCard(){
		if (!searchForm.shop.value) {showWarning("请选择加油站！");return};
		var ids = qt.getBoxValue();
		if (!ids)
			showWarning("请选择需要领用的PSAM卡。");
		else{
			if(showQuestion("是否领用这些PSAM卡？")){
				var shopId = searchForm.shop.value;
				DWR.call("cardMgntService.issueMgntCards",shopId,ids,function(result){
					showInformation("PSAM卡领用成功！");
					showIssueDet(result);
				},{blockScreen:true});
			}
		}
	}
	function onCancel(){
		dataMap = {}
		switchPage("readcardview");
		searchForm.reset()
		qt.dataSrc = {start:0,maxResult:100,total:100,objects:[]}
		qt.showTable();
	}
</script>
</head>
<body onload="load()">
<!--页面导航-->
<div class="nav">
<div id="nav">&nbsp;</div>
</div>
<div id="readcardview"><!--查询条件form-->
<div class="form">
<div class="formTitle">油站信息</div>
<form id="searchForm" name="searchForm"><input type="hidden"
	name="organization" /> <input type="hidden" name="cardType" /> <input
	type="hidden" name="shop" /> <input type="hidden" name="status"
	value="2" /> <input type="hidden" name="storeStatus" value="2" />
<table cellSpacing=0 cellPadding=4 width="100%" border=0>
	<tr>
		<td><label>油站名称</label> <input type="text" name="shopName"
			maxlength="64" readonly class="readonly"
			onblur="checkV(this,'',true)"><a class="orga" href="#"
			onclick="selectStation()">&nbsp;&nbsp;</a><span class="des">*</span></td>
		<td><label>油站编号</label> <input type="text" name="uniqueId"
			readonly class="readonly"></td>
	</tr>
</table>
</form>
</div>
<div id="cardlistview"></div>
<p>
<button id="selCardBtn" onclick="selCard()">读 卡</button>
<button id="issueCardBtn" onclick="issueOperCard()">领用卡片</button>
<button onclick="onCancel()">重 置</button>
</p>
</div>
<!--明细(新增)静态页面部分-->
<div id="detview" class="form" style="width: 100%; display: none;">
<div class="formTitle">
<div class="l">PSAM卡领用凭证</div>
<div class="r">
<button onclick="WebPrint.preview('billview')">打印预览</button>
<button onclick="WebPrint.print('billview')">打印</button>
<button onclick="onCancel();">返 回</button>
</div>
</div>
<div id="billview" align='center'></div>
</div>
</body>
</html>